package com.sdhs.examinemanage.service.impl;

import java.util.List;

import com.sdhs.common.enums.BusinessStatusEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sdhs.businessfile.domain.BusinessFile;
import com.sdhs.businessfile.service.IBusinessFileService;
import com.sdhs.common.enums.BusinessTypeEnum;
import com.sdhs.common.utils.DateUtils;
import com.sdhs.common.utils.SecurityUtils;
import com.sdhs.examinemanage.domain.GcExamineAppeal;
import com.sdhs.examinemanage.mapper.GcExamineAppealMapper;
import com.sdhs.examinemanage.service.IGcExamineAppealService;

/**
 * 项目考核申诉Service业务层处理
 * 
 * @author wanglei
 * @date 2025-03-13
 */
@Service
public class GcExamineAppealServiceImpl implements IGcExamineAppealService 
{
    @Autowired
    private GcExamineAppealMapper gcExamineAppealMapper;
    
    @Autowired
    private IBusinessFileService businessFileService;

    /**
     * 查询项目考核申诉
     * 
     * @param id 项目考核申诉主键
     * @return 项目考核申诉
     */
    @Override
    public GcExamineAppeal selectGcExamineAppealById(Long id)
    {
    	GcExamineAppeal examineAppeal = gcExamineAppealMapper.selectGcExamineAppealById(id);
    	List<BusinessFile> fileList = businessFileService.listByBusinessTypeAndId(BusinessTypeEnum.GC_EXAMINE_APPEAL.getCode(), String.valueOf(id));
    	examineAppeal.setFileList(fileList);
    	return examineAppeal;
    }

    /**
     * 查询项目考核申诉列表
     * 
     * @param gcExamineAppeal 项目考核申诉
     * @return 项目考核申诉
     */
    @Override
    public List<GcExamineAppeal> selectGcExamineAppealList(GcExamineAppeal gcExamineAppeal)
    {
        return gcExamineAppealMapper.selectGcExamineAppealList(gcExamineAppeal);
    }

    /**
     * 新增项目考核申诉
     * 
     * @param gcExamineAppeal 项目考核申诉
     * @return 结果
     */
    @Override
    public GcExamineAppeal insertGcExamineAppeal(GcExamineAppeal gcExamineAppeal)
    {
		gcExamineAppeal.setApprovalStatus(BusinessStatusEnum.DRAFT.getStatusValue());
		gcExamineAppeal.setCreater(SecurityUtils.getUsername());
        gcExamineAppeal.setCreateTime(DateUtils.getNowDate());
        gcExamineAppealMapper.insertGcExamineAppeal(gcExamineAppeal);
        businessFileService.saveFileBatch(BusinessTypeEnum.GC_EXAMINE_APPEAL.getCode(), String.valueOf(gcExamineAppeal.getId()), gcExamineAppeal.getFileList());
		return gcExamineAppeal;
    }

    /**
     * 修改项目考核申诉
     * 
     * @param gcExamineAppeal 项目考核申诉
     * @return 结果
     */
    @Override
    public int updateGcExamineAppeal(GcExamineAppeal gcExamineAppeal)
    {
		gcExamineAppeal.setUpdater(SecurityUtils.getUsername());
        gcExamineAppeal.setUpdateTime(DateUtils.getNowDate());
        int result = gcExamineAppealMapper.updateGcExamineAppeal(gcExamineAppeal);
        businessFileService.saveFileBatch(BusinessTypeEnum.GC_EXAMINE_APPEAL.getCode(), String.valueOf(gcExamineAppeal.getId()), gcExamineAppeal.getFileList());
		return result;
    }

    /**
     * 批量删除项目考核申诉
     * 
     * @param ids 需要删除的项目考核申诉主键
     * @return 结果
     */
    @Override
    public int deleteGcExamineAppealByIds(Long[] ids)
    {
        return gcExamineAppealMapper.deleteGcExamineAppealByIds(ids);
    }

    /**
     * 删除项目考核申诉信息
     * 
     * @param id 项目考核申诉主键
     * @return 结果
     */
    @Override
    public int deleteGcExamineAppealById(Long id)
    {
        return gcExamineAppealMapper.deleteGcExamineAppealById(id);
    }
}
